package com.five.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.admin.server.IconService;
import com.five.core.result.Result;
import com.five.pojo.dto.IconQueryDto;
import com.five.pojo.entity.Icon;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RequestMapping("/icon")
@RestController
public class IconController {
    @Resource
    private IconService iconService;
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(@RequestBody(required = false) IconQueryDto queryDto){
        Page<Icon> iconByTitle = iconService.findIconByTitle(queryDto);
        log.info("iconByTitle = " + iconByTitle);
        return Result.buildSuccess(iconByTitle.getTotal(),iconByTitle.getRecords());
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Icon icon){
        iconService.save(icon);
        log.info("icon = " + icon);
        return Result.buildSuccess();
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Icon icon){
        iconService.updateById(icon);
        log.info("icon = " + icon);
        return Result.buildSuccess();
    }
    @RequestMapping("/delete")
    public Result delete(Long id){
        iconService.removeById(id);
        log.info("id = " + id);
        return Result.buildSuccess();
    }
}
